import { Model } from '@vuex-orm/core';
import {getToken, setClientToken} from "../utils/auth";

export default class MinishopSkuAttrs extends Model {
    // This is the name used as module name of the Vuex Store.
    static entity = 'minishop_sku_attrs';

    // List of all fields (schema) of the post model. `this.attr` is used
    // for the generic field type. The argument is the default value.
    static fields() {
        return {
            id: this.attr(null),
            name: this.string(''),
            key: this.string(''),
            value: this.string(''),
            pid: this.number(''),
            spu_id: this.number(''),
            weigh: this.number(''),
            creator_id: this.attr(''),
            created_at: this.attr(''),
            updated_at: this.attr(''),
            deleted_at: this.attr(0)
        };
    }

    static fetchBySpuId(params) {
        return this.api().get(`/minishopSkuAttrs`,{params: params, persistBy: 'create' });
    }

    static insertParentData(params) {
        let result = this.api().post(`/minishopSkuAttr/insertParentData`,params,{save:false});
        console.log(result.response);
        if(result.response.data.code == 10000){
            console.log(result.response.data);
        }else{
            console.log(result.response.data.message);
        }
        return result;
    }

    static insertChildrenData(params) {
        console.log('insertChildrenData');
        console.log(params);
        let result = this.api().post(`/minishopSkuAttr/insertChildrenData`,params,{save:false});
        if(result.response.data.code == 10000){
            console.log(result.response.data);
        }else{
            console.log(result.response.data.message);
        }
        return result;
    }

}
